home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / objc.778 < prev    next >
Text File  |  1992-02-06  |  2KB  |  73 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;}
  2. \paperw13600
  3. \paperh8860
  4. \margl120
  5. \margr1000
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 C++ gdb bug workaround\
  8. \
  9. Q:  When I tried to trace my C++ program with gdb, gdb just crashes with a Bus Error message.  Why is this happening?\
  10. \
  11. A:  There is a problem with using gdb and C++, when you forward declare a class, then try to use the class as a static member of another class.  The following code snippet shows the problem, and how to work around it:\
  12. \
  13.  
  14. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f1\b\fs24\fc0     class A;
  15. \b0 \
  16.     \
  17.     class B\
  18.     \{\
  19.  
  20. \b         static  A *a;
  21. \b0 \
  22.     public:\
  23.         B()\{\};\
  24.     \};\
  25.     \
  26.     \
  27.     main()\
  28.     \{\
  29.         int i;\
  30.         i=2;\
  31.     \}\
  32.     \
  33.     class A\{\
  34.         int x;\
  35.     \};\
  36. \
  37.  
  38. \f0\fs28 Note that class B has a static class variable (or in the C++ jargon, a static class member) , but no instance variable (or in the C++ jargon, no member).  The workaround is to add a dummy instance variable to the class definition:\
  39. \
  40.  
  41. \f1\b\fs24     class A;
  42. \b0 \
  43.     \
  44.     class B\
  45.     \{\
  46.  
  47. \b         static    A *a;\
  48.             A *dummy;
  49. \b0 \
  50.     public:\
  51.         B()\{\};\
  52.     \};\
  53.     \
  54.     \
  55.     main()\
  56.     \{\
  57.         int i;\
  58.         i=2;\
  59.     \}\
  60.     \
  61.     class A\{\
  62.         int x;\
  63.     \};\
  64. \
  65. \
  66.  
  67. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28\fc0 QA778\
  68. \
  69. Not Valid for 1.0\
  70. Valid for 2.0\
  71. \
  72.  
  73.